package com.ruoyi.car.controller;

import java.util.List;

import com.ruoyi.car.vo.RecordAndListAndUseAndUserAndDeptVO;
import com.ruoyi.car.vo.RecordAndListAndUseVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.car.domain.TmdCarRecord;
import com.ruoyi.car.service.ITmdCarRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用车记录Controller
 * 
 * @author ruoyi
 * @date 2024-04-26
 */
@Controller
@RequestMapping("/car/record")
public class TmdCarRecordController extends BaseController
{
    private String prefix = "car/record";

    @Autowired
    private ITmdCarRecordService tmdCarRecordService;

    @RequiresPermissions("car:record:view")
    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

//    /**
//     * 查询用车记录列表
//     */
//    @RequiresPermissions("car:record:list")
//    @PostMapping("/list")
//    @ResponseBody
//    public TableDataInfo list(TmdCarRecord tmdCarRecord)
//    {
//        startPage();
//        List<TmdCarRecord> list = tmdCarRecordService.selectTmdCarRecordList(tmdCarRecord);
//        return getDataTable(list);
//    }

    /**
     * 查询用车记录列表
     */
    @RequiresPermissions("car:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RecordAndListAndUseVO tmdCarRecord)
    {
        startPage();
        List<RecordAndListAndUseVO> list = tmdCarRecordService.selectTmdCarRecordList(tmdCarRecord);
        return getDataTable(list);
    }

//    /**
//     * 导出用车记录列表
//     */
//    @RequiresPermissions("car:record:export")
//    @Log(title = "用车记录", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    @ResponseBody
//    public AjaxResult export(TmdCarRecord tmdCarRecord)
//    {
//        List<TmdCarRecord> list = tmdCarRecordService.selectTmdCarRecordList(tmdCarRecord);
//        ExcelUtil<TmdCarRecord> util = new ExcelUtil<TmdCarRecord>(TmdCarRecord.class);
//        return util.exportExcel(list, "用车记录数据");
//    }

    /**
     * 新增用车记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用车记录
     */
    @RequiresPermissions("car:record:add")
    @Log(title = "用车记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TmdCarRecord tmdCarRecord)
    {
        return toAjax(tmdCarRecordService.insertTmdCarRecord(tmdCarRecord));
    }

    /**
     * 查看用车记录
     */
    @RequiresPermissions("car:record:detail")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap)
    {
        RecordAndListAndUseAndUserAndDeptVO tmdCarRecord = tmdCarRecordService.selectTmdCarRecordById(id);
        mmap.put("tmdCarRecord", tmdCarRecord);
        return prefix + "/detail";
    }


    /**
     * 修改用车记录
     */
    @RequiresPermissions("car:record:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        RecordAndListAndUseAndUserAndDeptVO tmdCarRecord = tmdCarRecordService.selectTmdCarRecordById(id);
        mmap.put("tmdCarRecord", tmdCarRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存用车记录
     */
    @RequiresPermissions("car:record:edit")
    @Log(title = "用车记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TmdCarRecord tmdCarRecord)
    {
        return toAjax(tmdCarRecordService.updateTmdCarRecord(tmdCarRecord));
    }

    /**
     * 删除用车记录
     */
    @RequiresPermissions("car:record:remove")
    @Log(title = "用车记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tmdCarRecordService.deleteTmdCarRecordByIds(ids));
    }
}
